//获取系统时间
var newDate = '';
getLangDate();
//值小于10时，在前面补0
function dateFilter(date){
    if(date < 10){return "0"+date;}
    return date;
}
function getLangDate(){
	var storeName=sessionStorage.getItem("userName");
    var dateObj = new Date(); //表示当前系统时间的Date对象
    var year = dateObj.getFullYear(); //当前系统时间的完整年份值
    var month = dateObj.getMonth()+1; //当前系统时间的月份值
    var date = dateObj.getDate(); //当前系统时间的月份中的日
    var day = dateObj.getDay(); //当前系统时间中的星期值
    var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    var week = weeks[day]; //根据星期值，从数组中获取对应的星期字符串
    var hour = dateObj.getHours(); //当前系统时间的小时值
    var minute = dateObj.getMinutes(); //当前系统时间的分钟值
    var second = dateObj.getSeconds(); //当前系统时间的秒钟值
    var timeValue = "" +((hour >= 12) ? (hour >= 18) ? "晚上" : "下午" : "上午" ); //当前时间属于上午、晚上还是下午
    newDate = dateFilter(year)+"-"+dateFilter(month)+"-"+dateFilter(date);
    newTime = dateFilter(hour)+":"+dateFilter(minute)+":"+dateFilter(second);
    document.getElementById("nowTime").innerHTML =newTime; 
    document.getElementById("nowDate").innerHTML =newDate;
    
    setTimeout("getLangDate()",1000);
}

//根据节点获取当前节点下的岗位
function getRole(node,typeid){
	var jsonStr={"currentNodeId":node,"orderType.orderTypeId":typeid};
	var roleId="";
	$.ajax({
		url:"/wvms-web/flow/findOrderTemplate",
		data:jsonStr,
		dataType:"text",
		type:"post", 
		async:false,
		success:function(result){
			roleId=result;
		}
	});
	
	return roleId;
}

layui.use(['form','element','layer','jquery','table'],function(){
	
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        element = layui.element;
        $ = layui.jquery;
        var table =layui.table;
        var userId=getUserId();
        var tableIns = table.render({
            elem: '#businessApproval',
            url : "/wvms-web/flow/handListPage?"+"&time="+new Date().getTime(),
            where:{'userId':userId},
            page : false,
            hide:true,
            skin:"line",
            limits : [5,10,15],
            limit : 10,
            id : "businessApprovalTable",
            cols : [[
                {field: 'orderBaseInfo', title: '业务编号',align:"center",templet: '<div>{{d.orderBaseInfo.orderId}}</div>'},
                {field: 'orderType', title: '业务名称',align:"center",templet: '<div>{{d.orderType.orderTypeDesc}}</div>'},    
                {field: 'roleInfo', title: '业务类型',align:'center',templet: '<div>{{d.orderType.orderTypeName}}</div>'},
                {field: 'roleInfo', title: '处理人',align:'center',templet: '<div>{{d.userInfo.userName}}</div>'},              
                {field: 'orderType', title: '进度', align:'center',templet: '<div>{{d.currentNodeId}}/{{d.nodeCount}}</div>'},
                {title: '操作',templet:'#businessApprovalBar',align:"left"}
            ]]
        });
        //列表操作
        table.on('tool(businessApproval)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
          	//处理
            if(layEvent === 'edit'){                      	
            	var contentPage="IOBusinessManagement/business_approval/business_approval_add.html";
            	if(data.orderType.orderTypeId=="5002"||data.orderType.orderTypeId=="5003"){
            	
            		contentPage="IOBusinessManagement/business_approval/business_approval_add2.html";       		
            	}           	   	
             	 var index = layui.layer.open({
            		 
 		            title : "业务审批处理",
 		            type : 2,
 		            skin:"layui-layer-lan",
 		            content : contentPage,
 		            success : function(layero, index){
 		            	var body = layui.layer.getChildFrame('body', index);
 		            	if(data.orderType.orderTypeId=="5002"||data.orderType.orderTypeId=="5003"){
 		                  	//出库审批信息
		                 	body.find("#orderId").val(data.orderBaseInfo.orderId);  //业务编号
		                    body.find("#usernum").val(data.userInfo.userId);  //用户编号 */
		                    body.find("#roleId").val(getRole(data.currentNodeId,data.orderType.orderTypeId));  //岗位编号 */
		                    body.find(".orderName").val(data.orderType.orderTypeName);  //业务类型 
		                    body.find(".handlerName").val(data.creator);  //创建人名称
		                    body.find("#orderTypeId").val(data.orderType.orderTypeId);  //业务类型编码 
		                    body.find("#handlerId").val(data.userInfo.userId);  //变更人编码
		                    body.find(".countMoney").val("52103565");  //总金额编码
		                    body.find(".createDate").val(data.creationTime);  //创建时间
		                	body.find(".address").val("长安路支行营业厅");	//目的地
		                    body.find(".nodeNum").val(data.currentNodeId);  //节点编码
		                 	body.find("#userId").val(getUserId());		//当前用户编码		                 			                 		                 
 		            	}else{	            			            	
	            			//用户审批信息
	            			body.find("#roleId").val(getRole(data.currentNodeId,data.orderType.orderTypeId));//岗位编号
	            		 	body.find("#orderId").val(data.orderBaseInfo.orderId);  //业务编号
		                    body.find("#usernum").val(data.userInfo.userId);  //用户编号 */
		                    body.find(".orderName").val(data.orderType.orderTypeName);  //业务类型 */
		                    body.find(".handlerName").val(data.creator);  //变更人 */
		                    body.find("#orderTypeId").val(data.orderType.orderTypeId);  //业务类型编码 */
		                    body.find("#handlerId").val(data.userInfo.userId);  //变更人编码*/
		                    body.find(".createDate").val(data.creationTime);  //创建时间编码*/
		                    body.find(".changeReason").val(data.remark);  //变更原因*/
		                    body.find(".nodeNum").val(data.currentNodeId);  //节点编码*/
		                    body.find("#userId").val(getUserId());		//当前用户编码
 			                  var sex="男";
 		              		if(data.userInfo.userSex==0){
 		              			sex="男";
 		              		}else{
 		              			sex="女";
 		              		} 
 		                    body.find(".userSex").val(sex);  //性别
 		                    body.find(".cardNum").val(data.userInfo.cardNum);  //身份证号
 		                    body.find(".userAge").val(data.userInfo.userAge);  //年龄 
 		                   
 		                    if(data.remark!=null&&data.remark!=""){
 		                    	body.find(".remark").val(data.remark);  
 		                    }else{
 		                    	 body.find(".remark").val("无");
 		                    }
 		            	}
 		            		            	
 		                    form.render();
 		               
 		                setTimeout(function(){
 		                    layui.layer.tips('点击此处返回业务审批列表', '.layui-layer-setwin .layui-layer-close', {
 		                        tips: 3
 		                    });
 		                },500)
 		            }
 		        })
    		        layui.layer.full(index);
    		        window.sessionStorage.setItem("index",index);
    		        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
    		        $(window).on("resize",function(){
    		            layui.layer.full(window.sessionStorage.getItem("index"));
    		        })
            }
        
        });
        
        
        
        //根据当前登录用户名获取所属用户编码
    	function getUserId(){
    		var userName=sessionStorage.getItem("userName");
    		var jsonStr={"userName":userName};
    		var userid="";
    		$.ajax({
    			url:"/wvms-web/user/userAndRoleList",
    			data:jsonStr,
    			dataType:"json",
    			type:"post",
    			async:false,
    			success:function(result){
    				$.each(result.data,function(key,value){
    					userid=value.userInfo.userId;
    		    	
    				});
    				
    			}
    			
    		});

    		return userid;
    	}
    //上次登录时间【此处应该从接口获取，实际使用中请自行更换】
    $(".loginTime").html(newDate.split("日")[0]+"日</br>"+newDate.split("日")[1]);
    //icon动画
    $(".panel a").hover(function(){
        $(this).find(".layui-anim").addClass("layui-anim-scaleSpring");
    },function(){
        $(this).find(".layui-anim").removeClass("layui-anim-scaleSpring");
    })
    $(".panel a").click(function(){
        parent.addTab($(this));
    })

    //获取代办信息	   
    $.get("/wvms-web/flow/handList",function(data){
    	
    	var result=data.data;
    	
        var hotNewsHtml = '';    
        $(".Gtasks").html(hotNewsHtml);
     
    })
     //代办数量
    $.get("/wvms-web/flow/getCountOrderHand?UserId="+getUserId(),function(data){
    	 $(".commissionAll span").text(data);
    })
    //用户数量
    $.get("/wvms-web/user/userList",function(data){
        $(".userAll span").text(data.data.length);
    })
    //获取当前系统时间 
	function getTime(){
	    var mydate = new Date();
	    var str = "" + mydate.getFullYear() + "-";
	    str += (mydate.getMonth()+1) + "-";
	    str += mydate.getDate() +" ";
	    str+=mydate.getHours() + ":";
	    str+=mydate.getMinutes() + ":";
	    str+=mydate.getSeconds() + "";
	    return str;

	  
	}


})
